{% set pypi_name = 'freezer-web-ui' %}
{% set source = fetch_source('https://tarballs.openstack.org/freezer-web-ui/freezer-web-ui-master.tar.gz') %}
{% set upstream_version = upstream_version() %}
{% set rpm_release = '1' %}

%if 0%{?rhel} || 0%{?fedora}
%global http_dashboard_dir %{_datarootdir}/openstack-dashboard
%else
%global http_dashboard_dir /srv/www/openstack-dashboard
%endif
Name:           {{ py2name() }}
Version:        {{ py2rpmversion() }}
Release:        {{ py2rpmrelease() }}
Summary:        The Freezer Web UI
License:        {{ license('Apache-2.0') }}
Group:          Development/Languages/Python
URL:            https://docs.openstack.org/freezer
Source0:        {{ source|basename }}
BuildRequires:  fdupes
BuildRequires:  {{ py3('horizon') }}
BuildRequires:  openstack-macros
BuildRequires:  {{ py3('python-freezerclient') }}
Requires:       {{ py2pkg('horizon-plugin-freezer-ui') }} = %{version}
BuildArch:      noarch

%description
The Freezer UI Horizon plugin adds Freezer panel to the OpenStack dashboard.

%package -n    {{ py2pkg('horizon-plugin-freezer-ui') }}
Summary:       The Freezer Web UI - Python module
Requires:      {{ py3('Django') }}
Requires:      {{ py3('python-freezerclient') }}

%description -n {{ py2pkg('horizon-plugin-freezer-ui') }}
The Freezer UI Horizon plugin adds Freezer panel to the OpenStack dashboard.

%prep
%autosetup -n {{ pypi_name }}-{{upstream_version}}
%py_req_cleanup

%build
%py3_build

%install
%py3_install

install -m 0755 -d %{buildroot}%{http_dashboard_dir}/openstack_dashboard/enabled/
cp -a disaster_recovery/enabled/_50*.py* %{buildroot}%{http_dashboard_dir}/openstack_dashboard/enabled/

%fdupes %{buildroot}%{python2_sitelib}
%fdupes %{buildroot}%{http_dashboard_dir}

%post
su %{apache_user} -s /bin/sh -c "python3 %{http_dashboard_dir}/manage.py collectstatic --noinput --clear > /dev/null"

%postun
su %{apache_user} -s /bin/sh -c "python3 %{http_dashboard_dir}/manage.py collectstatic --noinput --clear > /dev/null"

%files
%doc ChangeLog README.rst
%license LICENSE
%{http_dashboard_dir}/openstack_dashboard/enabled/*.py*

%files -n {{ py2pkg('horizon-plugin-freezer-ui') }}
%doc README.rst
%license LICENSE
%{python3_sitelib}/disaster_recovery
%{python3_sitelib}/freezer_web_ui-*.egg-info

%changelog
